package Net::MySpaceIM::Services;

use strict;
use warnings FATAL => 'all';

our $MySpaceIM_serivces = {
        lc => {
                 service => 'Login Challenge',
                 action  => sub{
                          my $self = shift;
                          my $packet = shift;

                           # first reply to challenge with response
                           if($packet->{lc} == 1){
                                  my $resp = $self->challenge($self->{username}, $self->{password}, $packet->{nc});
                                  $self->send_pack("\\login2\\196610\\username\\".$self->{username}."\\response\\$resp\\clientver\\716\\langid\\1033\\imlang\\English\\reconn\\0\\status\\100\\id\\1\\final\\");
                          }

                           # this means we connected :)
                           elsif($packet->{lc} == 2){
                                 # set some data we will need for later.
                                 $self->{info}->{userid} = $packet->{userid};
                                  $self->{info}->{uniquenick} = $packet->{uniquenick};
                                 $self->{info}->{sesskey} = $packet->{sesskey};

                                 # set status to online :)
                                 #todo: change this when we write a "set status" sub
                                 $self->send_pack("\\status\\1\\sesskey\\".$packet->{sesskey}."\\statstring\\\\locstring\\userinfo;\\caps\\127\\final\\");

                                 # call connected event
                                 $self->call_event( $self, 'Connected', $self->{Connected});
                          }

                 }
        },
        error => {
                 service => 'Error',
                 action  => sub{
                          my $self = shift;
                          my $packet = shift;

                           #call error handler for any errors sent from myspace
                           $self->call_event( $self, 'Error', $packet->{err}, $packet->{errmsg});
                 }
        },
        bm => {
                 service => 'Buddy Message',
                 action  => sub{
                          my $self = shift;
                          my $packet = shift;

                           # got a normal message
                           if($packet->{bm} == 1){
                                   $self->call_event( $self, 'Message', $packet->{f}, $packet->{msg});
                           }
                 }
        },

};

1;